package com.imau.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class SqlSessionFactoryUtil {

    private static String path = "mybatis-config.xml";

    private static  SqlSessionFactory factory;

    private SqlSessionFactoryUtil()
    {

    }

    public static SqlSessionFactory getInstace(){

        if(factory==null)
        {
            InputStream resourceAsStream = null;
            try {

                resourceAsStream = Resources.getResourceAsStream(path);
                factory = new SqlSessionFactoryBuilder().build(resourceAsStream);

            } catch (IOException e) {

                throw new RuntimeException(e);
            }


        }

        return factory;
    }
}
